<!-- 反馈意见 -->
<template>
  <a-layout class="lanjian-content pdd">
    <div class="tableOperator">
      <div></div>
      <div class="input-box">
        <a-select placeholder="请选择问题分类" v-model="queryParam.Problems" :allowClear="true" class='m-r-8'>
          <a-select-option
            v-for="(item, i) in wtfl"
            :key="i"
            :value="item.value"
            :title="item.name">
            {{ item.name }}
          </a-select-option>
        </a-select>
        <a-input v-model.trim="queryParam.concreteProblems" class='m-r-8' placeholder="问题方面" :maxLength=50 />
        <a-input v-model.trim="queryParam.ProblemClassification" class='m-r-8' placeholder="具体问题" :maxLength=50 />
        <a-button type='primary' class='m-r-8 ClassA' @click='search' title='搜索'>
          <span class='icon iconfont'>&#xe666;</span>
        </a-button>
        <a-button class='resBtn ClassA' @click='loadtable' title='重置'>
          <span class='icon iconfont'>&#xe672;</span>
        </a-button>
      </div>
    </div>
    <a-table
      class="table-box"
      bordered
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      @change="tablePaginationChange"
      rowKey="id"
    >
      <span
        slot="action"
        slot-scope="record"
        class="actionIcons">
        <span  title="查看">
           <i class="icon iconfont" @click="see(record)">&#xe67b;</i>
        </span>
      </span>
    </a-table>
    <a-modal
      centered
      title="反馈意见"
      v-model:visible="visible"
      :confirm-loading="confirmLoading"
      :z-index="1000"
      :width="1000"
    >
      <a-form-model
        ref="ruleForm"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        :rules="rules"
        :model="ruleForm"
      >
        <table class="detailsBox">
          <tr class="detailstag">
            <td class="title">
              问题分类
            </td>
            <td class="content">
              {{ ruleForm.Problem}}
            </td>
          </tr>
          <tr class="detailstag">
            <td class="title">
              问题方面
            </td>
            <td class="content">
              {{ ruleForm.concreteProblems}}
            </td>
          </tr>
          <tr class="detailstag">
            <td class="title">
              具体问题
            </td>
            <td class="content">
              {{ ruleForm.ProblemClassification}}
            </td>
          </tr>
          <tr class="detailstag">
            <td class="title">
              整改建议
            </td>
            <td class="content">
              {{ ruleForm.remake}}
            </td>
          </tr>
        </table>
<!--        <a-form-model-item label="问题分类" class="formtabMax">
          <span>{{ ruleForm.Problem }}</span>
        </a-form-model-item>
        <a-form-model-item label="问题方面" class="formtabMax">
          <span>{{ ruleForm.concreteProblems }}</span>
        </a-form-model-item>
        <a-form-model-item label="具体问题" class="formtabMax">
          <span>{{ ruleForm.ProblemClassification }}</span>
        </a-form-model-item>
        <a-form-model-item label="整改建议" class="formtabMax">
          <span>{{ ruleForm.remake }}</span>
        </a-form-model-item>-->
      </a-form-model>
      <template slot="footer">
        <a-button @click="handleCancel">取消</a-button>
      </template>
    </a-modal>
  </a-layout>
</template>

<script>
import {
  fileParse,
  getFeedback, getFKdocs, getTempletes, streamToBuffer,
} from '@/utils/JsonTools';
import { getName } from '@/utils/getName';
import { dialog, shell } from '@electron/remote';
import { saveAs } from 'file-saver';
import * as win from '@electron/remote';
import * as path from 'path';
import { app } from 'electron';
import {getAppLocalPath, getProblemType, getStatusType} from '@/utils/common';
// eslint-disable-next-line no-unused-vars
// import dialog from 'electron'
const fs = require('fs');
export default {
  name: 'Feedback',
  data() {
    return {
      fkdoc: undefined,
      fkdocname: '意见反馈附件:无',
      // 列
      columns: [
        {
          title: '序号',
          width: 70,
          align: 'center',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '问题分类',
          dataIndex: 'Problems',
          key: 'Problems',
          align: 'center',
          ellipsis: true,
          customRender: (text, record, index) => {
            // eslint-disable-next-line no-empty,no-undef
            return getProblemType(record.Problems);
          },
        },
        {
          title: '问题方面',
          dataIndex: 'concreteProblems',
          key: 'concreteProblems',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '具体问题',
          dataIndex: 'ProblemClassification',
          key: 'ProblemClassification',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '整改建议',
          dataIndex: 'remake',
          key: 'remake',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '操作',
          key: 'operation',
          width: 100,
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      dataSource: [],
      queryParam: {
        ProblemClassification: undefined,
        Problems: undefined,
        concreteProblems: undefined,
      },
      // 分页参数
      pagination: {
        current: 1,
        // defaultCurrent: 1,
        total: 0, // 总数
        showSizeChanger: true,
        // 是否可以快速跳转至某页
        showQuickJumper: true,
        pageSizeOptions: ['10', '20', '40', '80', '100'],
        // showTotal: total => '共 ${total} 条', // 分页中显示总的数据
        // hideOnSinglePage: true, // 只有一页时是否隐藏分页器
        pageSize: 10, // 每页条数，所有页设置统一的条数
      },
      wtfl: [{
        value: '0',
        name: 'A：聚焦基层贯彻落实党的路线方针政策和党中央决策部署情况，进一步促进基层党组织和党员干部担当作为',
      }, {
        value: '1',
        name: 'B：聚焦群众身边腐败问题和不正之风，进一步增强群众获得感幸福感安全感',
      }, {
        value: '2',
        name: 'C：聚焦基层党组织软弱涣散，组织力欠缺问题，进一步强化政治功能、打造坚强战斗堡垒',
      }, {
        value: '3',
        name: 'D：整改落实情况',
      }],
      // 选中值
      ruleForm: {},
      // 表单标题内容宽度设置
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      // 表单规则
      rules: {},
      // 弹框显示
      visible: false,
      // 弹框加载状态
      confirmLoading: false,
    };
  },
  mounted() {
    this.loadtable();
    this.getFkfile();
  },
  methods: {
    getNowMilliSecond() {
      return Math.floor(Date.now());
    },
    down() {
      // var { remote } = require('electron').remote
      // console.log(remote)
      // const { dialog } = window.require('electron').remote
      // dialog.showMessageBoxSync({
      //   type: 'info',
      //   title: '这里是标题',
      //   message: '提示内容',
      //   detail: '额外信息'
      // })

      // eslint-disable-next-line no-unused-vars
      // const { dialog } = require('electron').remote
      // const res = dialog.showSaveDialogSync({
      //   title: '对话框窗口的标题',
      //   defaultPath: '', // 打开文件选择器的哪个路径 需要输入一个有效路径
      //   buttonLabel: '确认按钮文案',
      //   // 限制能够选择的文件为某些类型
      //   filters: [
      //     // { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
      //     // { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
      //     // { name: 'Custom File Type', extensions: ['as'] },
      //     // { name: 'All Files', extensions: ['*'] },
      //   ],
      //   nameFieldLabel: '替换文件', // “文件名”文本字段前面显示的文本自定义标签
      //   showsTagField: true, // 显示标签输入框，默认值为true
      //   properties: ['showHiddenFiles'],
      //   message: 'mac文件选择器title'
      // })
      // console.log('res', res)

      // 获取url:下载文件的url
      getTempletes().then(node => {
        // Note: Ie and Edge don't support the new File constructor,
        // so it's better to construct blobs and use saveAs(blob, filename)
        console.log(node);
        let fileb = fs.createReadStream(node.tmppath);
        streamToBuffer(fileb).then(res => {
          let data = res;
          let contents = new Uint8Array(data.length);
          for (let i = 0; i < data.length; i++) {
            contents[i] = data[i];
          }
          let usr = fs.readFileSync(getAppLocalPath()+'dbson/User.dbson', 'utf-8');
          let user = JSON.parse(usr);
          // eslint-disable-next-line eqeqeq
          saveAs.saveAs(new Blob([contents]), user.compName == undefined ? this.getNowMilliSecond() + '.xls' : user.compName + '-' + this.getNowMilliSecond() + '.xls');
        });
      });
    },
    getName,
    tablePaginationChange(pagination) {
      // 重新设置当前页
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
    },
    // 查询反馈意见
    loadtable() {
      this.queryParam.ProblemClassification = undefined;
      this.queryParam.Problems = undefined;
      this.queryParam.concreteProblems = undefined;
      getFeedback().then(res => {
          res.sort((a, b) => {
            if(a.serial_num<b.serial_num){
              return -1
            }else{
              return 1
            }
          })
          this.dataSource = [...res];
      });
    },
    // 查询反馈文件
    getFkfile() {
      getFKdocs().then(res => {
        if (res.fkdoc) {
          this.fkdoc = res.fkdoc;
          this.fkdocname = res.fkdocname;
        }
      });
    },
    openFdoc() {
      let fdocfile = fs.createReadStream(this.fkdoc);
      streamToBuffer(fdocfile).then(res => {
        let data = res;
        let contents = new Uint8Array(data.length);
        for (let i = 0; i < data.length; i++) {
          contents[i] = data[i];
        }
        // eslint-disable-next-line eqeqeq
        saveAs.saveAs(new Blob([contents]), this.fkdocname);
      });
    },
    // 搜索反馈意见
    search() {
      getFeedback().then(res => {
        let arr = [];
        let a, b, c;
        if (this.queryParam.ProblemClassification === undefined) {
          a = '';
        } else {
          a = this.queryParam.ProblemClassification;
        }
        if (this.queryParam.concreteProblems === undefined) {
          b = '';
        } else {
          b = this.queryParam.concreteProblems;
        }
        if (this.queryParam.Problems === undefined) {
          c = '';
        } else {
          c = this.queryParam.Problems + '';
        }
        //alert(c)
        console.log('fk1--', a);
        console.log('fk2--', b);
        console.log('fk3--', c);
        res.forEach(element => {
          if (element.ProblemClassification.indexOf(a) > -1 && (element.Problems+"").indexOf(c)> -1 && element.concreteProblems.indexOf(b) > -1) {
            arr.push(element);
          }
        });
        arr.sort((a, b) => {
          if(a.serial_num<b.serial_num){
            return -1
          }else{
            return 1
          }
        })
        this.dataSource = [...arr];
      });
    },
    see(record) {
      this.ruleForm = { ...record };
      this.ruleForm.Problem = getProblemType(record.Problems);
      this.visible = true;
    },
    handleOk(e) {
      this.visible = false;
    },
    handleCancel(e) {
      this.visible = false;
    },
  },
};
</script>
<style lang="scss">
// 滚动条背景颜色
.ant-form::-webkit-scrollbar,
.info::-webkit-scrollbar {
  height: 9px;
  width: 9px;
  background-color: #fcfcfc;
}

// 滚动条颜色
.ant-form::-webkit-scrollbar-thumb,
.info::-webkit-scrollbar-thumb {
  border-radius: 9px;
  background-color: #000000;
}

.ant-form-item label{
  font-weight: bold;
}

</style>

